﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

/*
 * Opisuje prymityw przedstawiający sferę.
 */
namespace Projekt.Models.Primitives
{
    public class Sphere : Primitive
    {
        /// <summary>
        /// Tworzy sferę o podanych parametrach
        /// </summary>
        /// <param name="Position">Punkt centralny sfery</param>
        /// <param name="Scale">Promienie na poszczególnych osiach</param>
        /// <param name="color">Kolor</param>
        public Sphere(Vector3 Position, Vector3 Scale, Color color, GraphicsDevice graphicsDevice, Engine game)
            : base(graphicsDevice, game)
        {
            this.Position = Position;
            this.Scale = Scale;
            this.Transforms = Matrix.Identity;
            this.game.Components.Add(this);

            for (int i = 0; i < 3; i++)
            {
                vertices.Add(new VertexPositionColor[100]);
                for (int j = 0; j < 100; j++)
                {
                    float angle = (float)(j / 100.0 * Math.PI * 2);
                    switch (i)
                    {
                        case 0:
                            vertices.Last()[j].Position = new Vector3((float)Math.Cos(angle), (float)Math.Sin(angle), 0);
                            break;
                        case 1:
                            vertices.Last()[j].Position = new Vector3((float)Math.Cos(angle), 0, (float)Math.Sin(angle));
                            break;
                        case 2:
                            vertices.Last()[j].Position = new Vector3(0, (float)Math.Cos(angle), (float)Math.Sin(angle));
                            break;
                    }                    
                    vertices.Last()[j].Color = color;
                }
                vertices.Last()[99] = vertices.Last()[0];
            }

            Transform();
        }

        public override string ToString()
        {
            return base.ToString() + "." + "sphere";
        }
    }
}
